<%--
  Created by IntelliJ IDEA.
  User: zhangjie
  Date: 2018/9/7
  Time: 9:37 AM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<html>
<head>
    <title>病人基本信息</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/paginate.css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/qulitity.css" type="text/css" type="text/css">
    <%--<link rel="stylesheet" href="../assets/css/views/modules/_common.scss">--%>
    <link rel="stylesheet" href="${assets}/css/views/department/departmentMgr.css">
    <link rel="stylesheet" href="${assets}/css/views/bloodScreening.css">
    <script src="../assets/js/views/vue.min.js"></script>
    <script type="text/javascript" src="${assets}/js/echarts.js"></script>
    <script src="${js}/jquery-1.9.1.min.js"></script>
    <script src="${js}/jquery.dataTables.js"></script>
    <script src="${frames}/Chronic/laydate/laydate.js"></script>
    <style>
        .color{
            margin:0 !important;
        }
        .btn{
             float:right ;
             width:100px;
             font-size:16px;
             line-height:28px;
             background:#35acfd !important;
             margin-right:15px !important;
             padding:0 !important;
         }
        .defualt{
            border:1px solid red !important;
        }
    </style>
</head>
<body>
<div>
    <%@ include file="../../breadline.jsp" %>
</div>
<div id="main">
    <div style="width:100%;">
        <div>
            <%@ include file="../../personalnews.jsp" %>
        </div>
        <div class="illness">
            <div style="margin-left:20px;padding-top:20px;padding-bottom:40px;">
                <h3 style="margin-bottom:16px;">高血压疾病筛查</h3>
                <div class="bpinfo" >
                    <div class="test" >
                        <div>
                            <span style="width:5px;padding-bottom:25px;background-color:#35acfd;display:inline-block;vertical-align:middle"></span>
                            <span class="topic">服务对象</span>
                            <button type="button" class="btn btn-info" @click="getVal()">
                                <img src="../assets/images/revise.png" alt="" style="width:16px;vertical-align: middle;">  保存
                            </button>
                        </div>
                        <div class="feritin">
                            <div id="isPatient">
                                <span class="title">辖区内35岁及以上常住居民中原发性高血压患者</span>
                                <span class="types">
                                    <input type="radio" value="1" name="class" id="r1">
                                    <label for="r1">是</label>
                                </span>
                                <span class="types">
                                    <input type="radio" value="0" name="class" id="r2">
                                    <label for="r2">否</label>
                                </span>
                            </div>
                        </div>
                        <div>
                            <span style="width:5px;padding-bottom:25px;background-color:#35acfd;display:inline-block;vertical-align:middle"></span>
                            <span class="topic">服务内容评估</span>
                        </div>
                        <div class="evaluate">
                            <div>
                                <label class="title">收缩压:</label>
                                <div class="inputWrap">
                                    <input type="text" class="SN" id="highPressure" name="highPressure">
                                    <span>mmHg</span>
                                </div>
                                <label class="title">舒张压:</label>
                                <div class="inputWrap">
                                    <input type="text" class="SN" id="lowPressure" name="lowPressure">
                                    <span>mmHg</span>
                                </div>

                                <label class="title">评估日期:</label>
                                <input name="screeningTime" id="screeningTime" type="text" class="lay-date" placeholder="选择时间" readonly>
                                <br>
                                <div class="manageLevel">
                                    <label class="title">管理级别:</label>
                                    <span class="types">
                                        <input type="radio" value="1" name="level" id="l1">
                                        <label for="l1">Ⅰ级</label>
                                    </span>
                                        <span class="types">
                                        <input type="radio" value="2" name="level" id="l2">
                                        <label for="l2">Ⅱ级</label>
                                    </span>
                                        <span class="types">
                                        <input type="radio" value="3" name="level" id="l3">
                                        <label for="l3">Ⅲ级</label>
                                    </span>
                                </div>

                            </div>
                        </div>
                        <div>
                            <span style="width:5px;padding-bottom:25px;background-color:#35acfd;display:inline-block;vertical-align:middle"></span>
                            <span class="topic">服务内容筛选</span>
                        </div>
                        <div class="serviceContent">
                            <div id="highBp">
                                <span class="title">（1）血压高值（收缩压130~139mmHG和/或舒张压85~89mmHG）</span>
                                <span class="types">
                                    <input type="radio" value="1" name="highBp" id="s1">
                                    <label for="s1">是</label>
                                </span>
                                <span class="types">
                                    <input type="radio" value="0" name="highBp" id="s2">
                                    <label for="s2">否</label>
                                </span>
                            </div>
                            <div id="isObesity">
                                <span class="title">（2）超重或肥胖，和（或）腹型肥胖：</span>
                                <span class="types">
                                    <input type="radio" value="1" name="obesity" id="t1">
                                    <label for="t1">是</label>
                                </span>
                                <span class="types">
                                    <input type="radio" value="0" name="obesity" id="t2">
                                    <label for="t2">否</label>
                                </span>
                                <p class="explain">
                                    超重：28Kg/㎡>BMI≥24Kg/㎡ ; 肥胖：BMI≥28Kg/㎡
                                    <br>
                                    腰围：男≥90cm（2.7尺），女≥85cm（2.6尺）为腹型肥胖
                                </p>
                            </div>
                            <div id="familyHistory">
                                <span class="title">（3）高血压家族史（一、二级亲属）</span>
                                <span class="types">
                                    <input type="radio" value="1" name="familyHistory" id="p1">
                                    <label for="p1">是</label>
                                </span>
                                <span class="types">
                                    <input type="radio" value="0" name="familyHistory" id="p2">
                                    <label for="p2">否</label>
                                </span>
                            </div>
                            <div id="isHighSalt">
                                <span class="title">（4）长期膳食高盐</span>
                                <span class="types">
                                    <input type="radio" value="1" name="diet" id="q1">
                                    <label for="q1">是</label>
                                </span>
                                <span class="types">
                                    <input type="radio" value="0" name="diet" id="q2">
                                    <label for="q2">否</label>
                                </span>
                            </div>
                            <div id="isExcessive">
                                <span class="title">（5）长期过量饮酒（每日饮白酒≥100ml）</span>
                                <span class="types">
                                    <input type="radio" value="1" name="excessiveDriking" id="v1">
                                    <label for="v1">是</label>
                                </span>
                                <span class="types">
                                    <input type="radio" value="0" name="excessiveDriking" id="v2">
                                    <label for="v2">否</label>
                                </span>
                            </div>
                            <div id="isGreater">
                                <span class="title">（6）年龄≥55岁</span>
                                <span class="types">
                                    <input type="radio" value="1" name="age" id="n1">
                                    <label for="n1">是</label>
                                </span>
                                <span class="types">
                                    <input type="radio" value="0" name="age" id="n2">
                                    <label for="n2">否</label>
                                </span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="tip display1">
                    <span><img src="../assets/images/iconTip.png" alt=""></span>
                    <span>您已占四项高危因素，建议每半年至少测量1次血压，并接受医务人员的生活方式指导！</span>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    var vm = new Vue({
        el : "#main",
        data: {
            infor: [],//病人基本信息data
            id:'',
            idCard:'',
            ispatient:'',
            highBp:'',
            isObesity:'',
            familyHistory:'',
            isHighSalt:'',
            isExcessive:'',
            isGreater:'',
            level:'',
            synchronous:false,
            btnText:'',
            dis:false
        },
        methods:{
            //修改病人基本信息
            addDevice:function(){
                let that= this;
                window.parent.showNewModelIframe("${URL_PATIENT_PATIENT}?id="+that.infor.id+'&diseasesType='+that.diseasesType,800,650);
            },
            //保存血压筛查信息
            getVal:function(){
                let _this=this;
                var INPUT=$('.bpinfo  input[value="1"]:checked');
                var INPUT1=$("#isPatient input");
                var INPUT2=$("#highBp input");
                var INPUT3=$("#isObesity input");
                var INPUT4=$("#familyHistory input");
                var INPUT5=$("#isHighSalt input");
                var INPUT6=$("#isExcessive input");
                var INPUT7=$("#isGreater input");
                var INPUT8=$(".manageLevel input");
                for(var i=0;i<INPUT1.length;i++){
                    if(INPUT1[i].checked==0){
                        _this.ispatient=1;
                    }else{
                        _this.ispatient=0;
                    }
                }
                for(var i=0;i<INPUT2.length;i++){
                    if(INPUT2[i].checked==0){
                        _this.highBp=1;
                    }else{
                        _this.highBp=0;
                    }
                }
                for(var i=0;i<INPUT3.length;i++){
                    if(INPUT3[i].checked==0){
                        _this.isObesity=1;
                    }else{
                        _this.isObesity=0;
                    }
                }
                for(var i=0;i<INPUT4.length;i++){
                    if(INPUT4[i].checked==0){
                        _this.familyHistory=1;
                    }else{
                        _this.familyHistory=0;
                    }
                }
                for(var i=0;i<INPUT5.length;i++){
                    if(INPUT5[i].checked==0){
                        _this.isHighSalt=1;
                    }else{
                        _this.isHighSalt=0;
                    }
                }
                for(var i=0;i<INPUT6.length;i++){
                    if(INPUT6[i].checked==0){
                        _this.isExcessive=1;
                    }else{
                        _this.isExcessive=0;
                    }
                }
                for(var i=0;i<INPUT7.length;i++) {
                    if (INPUT7[i].checked == 0) {
                        _this.isGreater = 1;
                    } else {
                        _this.isGreater = 0;
                    }
                }
                for(var i=0;i<INPUT8.length;i++){
                    if (INPUT8[0].checked == 1) {
                        _this.level = 1;
                    } else if (INPUT8[1].checked == 1) {
                        _this.level = 2;
                    } else {
                        _this.level = 3;
                    }
                }
                if(INPUT.length>=4){
                    $(".tip").removeClass('display1');
                }else{
                    $(".tip").addClass('display1');
                }
                var app = []
//                var offset = $('#isPatient').offset().top
//                parent.$("html,body").animate({ scrollTop: offset}, 0);
                if("${id}"==''){
                    if($('#isPatient input:checked').length != 1 || $("#highPressure").val()==''||$("#lowPressure").val()==''|| $('#screeningTime').val() == "" || $(".manageLevel input[type='radio']:checked").length != 1){
                        if( $('#isPatient input:checked').length != 1 ){
                            // 服务对象未选择
                            if( $('#isPatient').children(":last").hasClass('defalts') ){

                            }else{
                                $('#isPatient').children(":last").after('<span class="defalts" style="margin-left:10px;color:red;font-size:15px;">'+'该选项未选择'+'</span>')
                                app.push($('#isPatient'))
                            }
                        }else{
                            if( $('#isPatient .defalts') ){
                                $('#isPatient .defalts').remove()
                            }
                        }
                        if(app[0]){
                            var offset = $(app[0]).offset().top
                            parent.$("html,body").animate({ scrollTop: offset}, 0);
                        }
                        if( $("#highPressure").val()==''||$("#lowPressure").val()==''|| $('#screeningTime').val() == "" ){
                            if( $('#screeningTime').val() == "" ){
                                $('#screeningTime').attr('placeholder','请输入数值')
                                $('#screeningTime').addClass('defualt')
                            }
                            var inputs = $("input[type='text']")
                            for( var a = 0; a < inputs.length-1; a++ ){
                                if( $(inputs[a]).val() === "" ){
                                    $(inputs[a]).attr('placeholder','请输入数值')
                                    $(inputs[a]).parent('.inputWrap').addClass('defualt')
                                }
                            }
                            if( $("#highPressure").val() !='' ){
                                if( $('#highPressure .defualt') ){
                                    $('#highPressure').parent('.inputWrap').removeClass('defualt')
                                }
                            }
                            if( $("#lowPressure").val() != '' ){
                                if( $('#lowPressure .defualt') ){
                                    $('#lowPressure').parent('.inputWrap').removeClass('defualt')
                                }
                            }
                            if( $('#screeningTime').val() != '' ){
                                if( $('#screeningTime').hasClass('defualt') ){
                                    $('#screeningTime').removeClass('defualt')
                                }
                            }
                        }
                        if( $(".manageLevel input[type='radio']:checked").length != 1 ){
                            if( $('.manageLevel').children(":last").hasClass('defalts') ){

                            }else{
                                $('.manageLevel').children(":last").after('<span class="defalts" style="margin-left:10px;color:red;font-size:15px;">'+'该选项未选择'+'</span>')
                            }
                        }else{
                            if( $('.manageLevel .defalts') ){
                                $('.manageLevel .defalts').remove()
                            }
                        }
                    }else{
                        $.ajax({
                            url:"${URL_SCREENING_SAVEBP}",
                            type:'post',
                            dataType: "json",
                            data:{
                                idCard:'${idcard}',
                                patient:_this.ispatient,
                                value:_this.highBp,
                                fat:_this.isObesity,
                                family:_this.familyHistory,
                                salt:_this.isHighSalt,
                                drink:_this.isExcessive,
                                old:_this.isGreater,
                                highPressure:$('#highPressure').val(),
                                lowPressure:$('#lowPressure').val(),
                                screeningTime:$("#screeningTime").val(),
                                level:_this.level
                            },
                            success: function(data) {
                                console.log(data);
                                if(data.success){
                                    parent.showSrc('${URL_SCREENING_BPSCREENINGS}?idcard=' + '${idcard}')
                                }else{
                                    alert("保存失败！");
                                }
                            }
                        })
                    }
                }else{
                    if($('#isPatient input:checked').length != 1 || $("#highPressure").val()==''||$("#lowPressure").val()==''|| $('#screeningTime').val() == "" || $(".manageLevel input[type='radio']:checked").length != 1){
                        if( $('#isPatient input:checked').length != 1 ){
                            // 服务对象未选择
                            if( $('#isPatient').children(":last").hasClass('defalts') ){

                            }else{
                                $('#isPatient').children(":last").after('<span class="defalts" style="margin-left:10px;color:red;font-size:15px;">'+'该题目未选择'+'</span>')
                                app.push($('#isPatient'))
                            }
                        }else{
                            if( $('#isPatient .defalts') ){
                                $('#isPatient .defalts').remove()
                            }
                        }
                        if(app[0]){
                            var offset = $(app[0]).offset().top
                            parent.$("html,body").animate({ scrollTop: offset}, 0);
                        }
                        if( $("#highPressure").val()==''||$("#lowPressure").val()==''|| $('#screeningTime').val() == "" ){
                            if( $('#screeningTime').val() == "" ){
                                $('#screeningTime').attr('placeholder','请输入数值')
                                $('#screeningTime').addClass('defualt')
                            }
                            var inputs = $("input[type='text']")
                            for( var a = 0; a < inputs.length-1; a++ ){
                                if( $(inputs[a]).val() === "" ){
                                    $(inputs[a]).attr('placeholder','请输入数值')
                                    $(inputs[a]).parent('.inputWrap').addClass('defualt')
                                }
                            }
                            if( $("#highPressure").val() !='' ){
                                if( $('#highPressure .defalts') ){
                                    $('#highPressure').parent('.inputWrap').removeClass('defualt')
                                }
                            }
                            if( $("#lowPressure").val() != '' ){
                                if( $('#lowPressure .defalts') ){
                                    $('#lowPressure').parent('.inputWrap').removeClass('defualt')
                                }
                            }
                            if( $('#screeningTime').val() != '' ){
                                if( $('#screeningTime').hasClass('defualt') ){
                                    $('#screeningTime').removeClass('defualt')
                                }
                            }
                        }
                        if( $(".manageLevel input[type='radio']:checked").length != 1 ){
                            if( $('.manageLevel').children(":last").hasClass('defalts') ){

                            }else{
                                $('.manageLevel').children(":last").after('<span class="defalts" style="margin-left:10px;color:red;font-size:15px;">'+'该题目未选择'+'</span>')
                            }
                        }else{
                            if( $('.manageLevel .defalts') ){
                                $('.manageLevel .defalts').remove()
                            }
                        }
                    }else{
                        $.ajax({
                            url:"${URL_SCREENING_SAVEBP}",
                            type:'post',
                            dataType: "json",
                            data:{
                                id:'${id}',
                                idCard:'${idcard}',
                                patient:_this.ispatient,
                                value:_this.highBp,
                                fat:_this.isObesity,
                                family:_this.familyHistory,
                                salt:_this.isHighSalt,
                                drink:_this.isExcessive,
                                old:_this.isGreater,
                                highPressure:$('#highPressure').val(),
                                lowPressure:$('#lowPressure').val(),
                                screeningTime:$("#screeningTime").val(),
                                level:_this.level
                            },
                            success: function(data) {
                                console.log(data);
                                if(data.success){
                                    parent.showSrc('${URL_SCREENING_BPSCREENINGS}?idcard=' + '${idcard}')
                                }else{
                                    alert("保存失败！");
                                }
                            }
                        })
                    }
                }

            },
            Synchronous(e){
                let that = this
                $.ajax({
                    url:'${URL_PATIENT_UPDATEPATIENT}',
                    data:{
                        id:that.infor.id,
                        synchronization:'1'
                    },
                    type:'post',
                    dataType:'json',
                    success:function(data){
                        console.log(data)
                        if(data.success){
                            e.target.disabled = true;
                            e.target.innerText = '正在同步'
                            that.setTime()
                        }else{
                            window.parent.showNewModelIframe('${URL_COMMON_TOTIPS}?title='+data.msg,300,200)
                        }
                    }
                })
            },
            setTime(){
                let that = this
                setInterval(function(){
                    $.ajax({
                        url:'${URL_PATIENT_UPDATEPATIENT}',
                        data:{
                            id:that.infor.id,
                            synchronization:'1'
                        },
                        type:'post',
                        dataType:'json',
                        success:function(data){

                        }
                    })
                },10000)
            }
        },
        mounted() {
            let that = this;
            var href = location.search.split('?')[1];
            var arr = href.split('&')[0];
            var url = arr.split('=')[1];
            // 获取病人基本信息
            $.ajax({
                url:"${URL_PATIENT_PATIENTINFO}",
                type:'post',
                dataType: "json",
                data:{
                    idCard:'${idcard}'
                },
                success: function(data) {
                    that.infor = data.data;
                    that.id=that.infor.id;
                    var href = that.infor.diseasesType
//                    that.infor.diseasesType = Type(that.infor.diseasesType)
                    that.idCard='${idcard}';
                    sessionStorage.setItem('BMI',that.infor.bMI);
                    sessionStorage.setItem('age',that.infor.age);
                    sessionStorage.setItem('gender',that.infor.sex);
                    sessionStorage.setItem('waist',that.infor.waist);
                }
            })

        }
    })
    $(document).ready(function() {
        initLayDate('#screeningTime');
        var pBMI=sessionStorage.getItem('BMI');
        var pAge=sessionStorage.getItem('age');
        if(pBMI>=24){
            $("#s1").attr("checked","checked");
        }
        if(pAge>=55){
            $("#n1").attr("checked","checked");
        }
        $(".bpinfo  input").each(function(index){
            $(this).click(function(){
                var checkedNum=$('.bpinfo  input[value="1"]:checked').length;
                if(checkedNum>=4){
                    $('.tip').removeClass('display1');
                }else{
                    $('.tip').addClass('display1');
                }
            });
        });
        if("${id}"!='') {
            //获取糖尿病疾病筛查信息
            $.ajax({
                url: "${URL_SCREENING_BPDATA}",
                type:'post',
                dataType: "json",
                data:{
                    id:'${id}'
                },
                success: function(data) {
                    console.log(data)
                    if(data.data.patient){
                        $("#r1").attr("checked","checked");
                    }else{
                        $("#r2").attr("checked","checked");
                    }
                    if(data.data.value||pBMI>=24){
                        $("#s1").attr("checked","checked");
                    }else{
                        $("#s2").attr("checked","checked");
                    }
                    if(data.data.fat){
                        $("#t1").attr("checked","checked");
                    }else{
                        $("#t2").attr("checked","checked");
                    }
                    if(data.data.family){
                        $("#p1").attr("checked","checked");
                    }else{
                        $("#p2").attr("checked","checked");
                    }
                    if(data.data.salt){
                        $("#q1").attr("checked","checked");
                    }else{
                        $("#q2").attr("checked","checked");
                    }
                    if(data.data.drink){
                        $("#v1").attr("checked","checked");
                    }else{
                        $("#v2").attr("checked","checked");
                    }
                    if(data.data.old||pAge>=55){
                        $("#n1").attr("checked","checked");
                    }else{
                        $("#n2").attr("checked","checked");
                    }
                    if(data.data.level=='1'){
                        $("#l1").attr("checked","checked");
                    }else if(data.data.level=='2'){
                        $("#l2").attr("checked","checked");
                    }else{
                        $("#l3").attr("checked","checked");
                    }
                    $("#highPressure").val(data.data.highPressure);
                    $("#lowPressure").val(data.data.lowPressure);
                    $("#screeningTime").val(data.data.screeningTime);
                    if($('.bpinfo  input[value="1"]:checked').length>=4){
                        $('.tip').removeClass('display1');
                    }
                }
            })
        }else{
            if(parseInt(sessionStorage.getItem('age'))>=55){
                $("#n1").attr("checked","checked");
            }
            if(sessionStorage.getItem('gender')=='女'){
                if(parseInt(sessionStorage.getItem('BMI'))>=24||parseInt(sessionStorage.getItem('waist'))>=85){
                    $("#t1").attr("checked","checked");
                }
            }else{
                if(parseInt(sessionStorage.getItem('BMI'))>=24||parseInt(sessionStorage.getItem('waist'))>=90){
                    $("#t1").attr("checked","checked");
                }
            }
            $.ajax({
                url:"${URL_PPPATIENTBASE_PATIENTDATA}",
                type:'get',
                dataType: "json",
                data:{
                    idCard:"${idcard}"
                },
                success: function(data) {
                    if( data.data != null ){
                        $('#highPressure').val(data.data.highPressure)
                        $('#lowPressure').val(data.data.lowPressure)
                    }
                }
            })
        }
    })
    function initLayDate(id) {
        laydate({
            elem: id,
            istime: true,
            format: 'YYYY-MM-DD',
            choose: function (dates) { //选择好日期的回调
                // initTablePatient();
            }
        })
    }
</script>
</body>
</html>
